package cn.njupt.gis.svg;

import java.awt.Color;
import java.util.List;

import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGGraphics2DIOException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

public class Gml2Svg {
	private SVGGraphics2D g2d = null;
	public Gml2Svg()
	{
		// Get a DOMImplementation.
		DOMImplementation domImpl = GenericDOMImplementation
				.getDOMImplementation();
		// Create an instance of org.w3c.dom.Document.
		String svgNS = "http://www.w3.org/2000/svg";
		Document document = domImpl.createDocument(svgNS, "svg", null); 
		g2d = new SVGGraphics2D(document);
		g2d.setPaint(Color.yellow);
 
	}
	public void drawPolygon(List<SvgPoint> points)
	{
		int len = points.size();
		for(int i=1;i<len;i++)
		{
			SvgPoint point0 = points.get(i);
			SvgPoint point1 = points.get(i-1);
 
			g2d.drawLine(point0.getX(), point0.getY(), point1.getX(), point1.getY());
		}
	}
	public void writeSvgFile(String fileName) throws Exception
	{
		g2d.stream(fileName);
	}
}
